<extend name="Public:base" />
<block name="content">
    <form method="post" id="validation-form" action="{:U('Coupon/del')}">
    <table class="table table-striped table-bordered table-hover search-form" id="nav-table">
        <thead>
            <th>电子券号：<input name="number" type="text"  value="{:I('number')}" />
            电子券名称：<input name="name" type="text"  value="{:I('name')}" />
            <a class="btn btn-primary radius5 btn-sm" href="javascript:;" id="search" url="{:U('Coupon/CouponInUse')}">查询</a>
            <input  style="{$delete==1?'':'display: none'}" id="submitBtn" type="submit"  value="删除"  class="btn btn-danger radius5 btn-sm" >
            </th>
        </thead>
    </table>
    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover" id="mytable">
            <thead>
            <tr>
                <th class="center"><input id="CheckAll" type="checkbox" /></th>
                <th>电子券号</th>
                <th class="col-xs-1">电子券名称</th>
                <th>面值</th>
                <th>可用范围</th>
                <th>领取条件</th>
                <th>状态</th>
                <th>有效期</th>
                <th>类型</th>
                <th>创建时间</th>
                <th>领取数</th>
                <th>使用数</th>
            </tr>
            </thead>
            <tbody>
            <volist name="Coupon" id="vo">
                <tr>
                    <td  class="center"><input name="Del[]" value="{$vo.volume_id}" type="checkbox" /></td>
                    <td>{$vo.volume_number}</td>
                    <td>{$vo.volume_name}</td>
                    <td>¥{$vo.total}</td>
                    <td>{$vo.category}</td>
                    <td>订单满{$vo.min}可用</td>
                    <td>停用</td>
                    <td>开始时间：{$vo.start_time}<br/>结束时间：{$vo.end_time}</td>
                    <td><?php
						switch($vo['type']){
							case '1':
							echo '<span class="yellow bold">代金券</span>';
                        break;
                        case '2':
                        echo '<span class="blue bold">现金券</span>';
                        break;}
                        ?>
                    </td>
                    <td>{$vo.add_time}</td>
                    <td>{$vo.get_count}</td>
                    <td>{$vo.use_count}</td>
                </tr>
            </volist>
            <tr>
                <td colspan="20" class="page">{$page}</td>
            </tr>
            </tbody>
        </table>
    </div>
     </form>
</block>
<block name="javascript">
    <script>
        $(function(){

            $("#search").click(function () {
                var url = $(this).attr('url');
                var query = $('.search-form').find('input,select').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
                query = query.replace(/^&/g, '');
                if (url.indexOf('?') > 0) {
                    url += '&' + query;
                } else {
                    url += '?' + query;
                }
                window.location.href = url;
            });

            $('#CheckAll').click(function () {
                $("input[name='Del[]']").prop('checked', this.checked);
            })

            $("#submitBtn").click(function(){
                var result = new Array(), str = '';
                $('input[name="Del[]"]:checked').each(function () {
                    result.push($(this).val());
                });
                var str = result.join(',');
                if (str == '') {
                    $.jbox.info('没有选中任何数据！','提示');
                    return false;
                }
                var submit = function (v, h, f) {
                    if (v == 'ok') {
                        $('#validation-form').ajaxSubmit(function(data){
                            if(data=='1'){
                                $.jbox.tip("正在删除数据...", 'loading');
                                // 模拟2秒后完成操作
                                window.setTimeout(function () { $.jbox.tip('删除成功。', 'success');location.reload()}, 1000);
                            }else if(data=='2'){
                                $.jbox.info("删除失败!",'提示');
                            }
                        });
                    }
                    else if (v == 'cancel') {
                        // 取消
                    }

                    return true; //close
                };

                $.jbox.confirm("确定要删除数据吗？", "提示", submit);

                return false;
            });

        });
    </script>
</block>